package com.br.android.widing.adapter;

import java.text.DecimalFormat;
import java.util.Currency;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.br.android.widing.R;
import com.br.android.widing.entity.Gasto;

public class ListGastosAdapter extends BaseAdapter {

	private Context context;
	private List<Gasto> listGastos;

	public ListGastosAdapter(Context context, List<Gasto> listGastos){
		this.context = context;
		this.listGastos = listGastos;
	}

	@Override
	public int getCount() {
		return listGastos.size();
	}

	@Override
	public Object getItem(int position) {
		return listGastos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Gasto gasto = listGastos.get(position);

		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.layout_adapter_list_gastos, null);

		TextView textViewGasto = (TextView) view.findViewById(R.id.textViewAdapterGasto);
		TextView textViewCategoria = (TextView) view.findViewById(R.id.textViewAdapterCategoria);
		TextView textViewData = (TextView) view.findViewById(R.id.textViewAdapterData);
		TextView textViewValor = (TextView) view.findViewById(R.id.textViewAdapterValor);

		textViewGasto.setText(gasto.getNomeGasto());
		textViewCategoria.setText(gasto.getCategoria());
		textViewData.setText(gasto.getDataCadastro());

		Currency currency = Currency.getInstance(Locale.getDefault());

		DecimalFormat format = new DecimalFormat(currency.getSymbol() + " ###,###,##0.00");

		textViewValor.setText(format.format(gasto.getValor()));

		return view;
	}

}
